# -*- coding: utf-8 -*-
# @Organization  : asiainfo
# @Author        : 周伟东
# @Time          : 2021/1/7 11:49
# @Function      : 基本 dao 操作
import logging

from app.dao import Session


class BaseDao:
    def save(self, entity):
        """
        保存
        return:
        """
        session = Session()
        try:
            session.add(entity)
            session.commit()
            return True
        except Exception as e:
            session.rollback()
            logging.error("添加失败", e)
            raise False
        finally:
            session.close()

    def insert_bulk(self, entity_list):
        """
        批量插入
        return: True or False
        """
        session = Session()
        try:
            session.add_all(entity_list)
            session.commit()
            return True
        except Exception as e:
            session.rollback()
            logging.error("添加失败", e)
            raise False
        finally:
            session.close()
